import random

import requests


def get():
    alist = ['中','华','为','魅','族','牛']
    name = alist[random.randint(0,6)]+alist[random.randint(0,6)]
    return name


if __name__ == '__main__':
    url = 'http://127.0.0.1:6688'
    qqq = requests.Session()
    usr = {'account': 'admin',
           'password': 'admin',
           'code': '1234'}
    header = {'X-Requested-With': 'XMLHttpRequest'}

    login = qqq.post(url+'/admin/account/login.html',data=usr,headers=header)
    print(login.text)

    # 添加品牌
    pp = {'name': '华为1',
          'initial': 'H',
          'image': 'uploads/images/2022021111014949ae08187.png',
          'sort': 5,
          'is_show': 1,
          'remark': '中华有为'
          }
    addpp = qqq.post(url+'/admin/goods_brand/add.html',data=pp,headers=header)
    print(addpp.text)
    # 查询品牌
    cxpp = qqq.get(url+'/admin/goods_brand/lists.html',params={'page':1,'limit':10},headers=header)
    print(cxpp.text)
    id = cxpp.json()['data']['list'][0]['id']

    # 修改品牌
    uppp = {'id':id,
    'name':'华为666',
    'initial':'H',
    'image':'66.jpg',
    'sort':1,
    'is_show':1,
    'remark':'荣耀'
    }
    up_pp = qqq.post(url+'/admin/goods_brand/edit.html',data=uppp,headers=header)
    print(up_pp.text)